package com.rst.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rst.model.Qualification;

@Repository
@Transactional
public class QualificationDAO {

	@Autowired
	private SessionFactory sessionFactory;

	public void saveQualification(Qualification qualification) {
		sessionFactory.getCurrentSession().saveOrUpdate(qualification);			
	}

	public Qualification getQualificationById(Long qualificationId) {
	    Session session = sessionFactory.getCurrentSession();
	    Qualification qualification = (Qualification)session.get(Qualification.class, qualificationId);
		return qualification;
	}

	@SuppressWarnings("unchecked")
	public List<Qualification> getQualificationList() {
		Session session = sessionFactory.getCurrentSession();
	    String str = "FROM Qualification q WHERE q.status = :status  ";
	    	
	    Query query = session.createQuery(str);
	    query.setParameter("status",  Qualification.ACTIVE);
		return query.list();
	}
}




